<?php

declare(strict_types=1);

namespace App\Model\Ocpc;

use Hyperf\DbConnection\Model\Model;

class OcpcBaiduUser extends Model
{
    protected $table = 'ocpc_baidu_user';
    protected $fillable = ['user_id', 'ocpc_id', 'url','channel','akeys'];

    public static function addRelation($data)
    {
        $data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s');
        return self::insertGetId($data);
    }

    public static function getUrlByUserId($userId,$channel)
    {
        $res = self::where('user_id',$userId)->where('channel',$channel)->first();
        if(!empty($res)) return $res->toArray();
        return [];
    }
}